<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var t = async_test("XMLHttpRequest: Recover from error by calling open() on the same XHR inside an error handler");
t.step(function() {
    var req = new XMLHttpRequest;
    req.open("GET", "http://localhost:0/", true);
    req.onreadystatechange = t.step_func(function() {
        if (req.readyState != XMLHttpRequest.DONE)
            return;

        assert_equals(0, req.status, "status of the first request should be 0");

        req.onreadystatechange = t.step_func(function() {
            if (req.readyState != XMLHttpRequest.DONE)
                return;

            assert_equals(200, req.status, "status of the second request should be 200");
            t.done();
        });

        req.open("GET", "resources/zero-length.txt", true);
        req.send();
    });
    req.send();
});
</script>
